<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>请输入提取码</title>
<style>
    .positionCode{
        width: 100%;
        height: 100%;
        background: #eef2f6;
        position: fixed;
        top: 0;
        left: 0;
    }
    .codeBox{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        padding: 20px 30px 40px;
        background: #fff;
        width: 400px;
        border-radius: 4px;
    }
    .codeBox p{
        padding: 0 0 5px;
        margin: 20px 0 10px;
        color: #666;
        font-size: 14px;
        font-weight: 500;
    }
    .codeDiv{
        height: 36px;
        margin-bottom: 15px;
        line-height: 36px;
    }
    .codeDiv input{
        display: inline-block;
        width: 280px;
        border: 1px solid #ccc;
        height: 36px;
        border-radius: 4px;
    }
    .codeDiv button{
        display: inline-block;
        margin-left: 30px;
        width: 76px;
        font-size: 14px;
        color: #fff;
        height: 36px;
        border: 1px solid #09AAFF;
        text-align: center;
        background: #09AAFF;
        text-decoration: none;
        white-space: nowrap;
        outline: 0;
        border-radius: 4px;
    }
    .getFail{
        color: #ff5858;
        position: absolute;
        bottom: 20px;
        left: 30px;
        font-size: 12px;
        display: none;
    }
</style>
</head>
<body>
<div class="positionCode">
    <div class="codeBox">
        <p>请输入提取码：</p>
        <div class="codeDiv">
            <input class="code" type="text" />
            <button class="getText">提取文件</button>
        </div>
        <div class="getFail">提取码错误</div>
        <input type="hidden" id="fileId" th:value="${fileId}">
        <input type="hidden" id="uuid" th:value="${uuid}">
    </div>
</div>
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script>
    $(".getText").click(function () {
        var code = $(".code").val();
        if(code == ''){
            $(".getFail").html('请输入提取码再提取文件');s
            $(".getFail").show();
        }else {
            //判断文件是否可以下载
            $.ajax({
                url : "/sys/userFile/judeDownloadFile",
                type : "post",
                data : {
                    'fileId' : $("#fileId").val(),
                    'uuid' : $("#uuid").val(),
                    'shareCode' : code,
                    'flag' : "2"
                },
                success : function(r) {
                    if (r.code==0) {
                        $(".getFail").html("");
                        window.location.href = "/sys/userFile/downloadFile?uuid=" + $("#uuid").val() + "&shareCode=" + code + "&fileId=" + $("#fileId").val();
                    }else{
                        // 验证码错误
                        $(".getFail").html(r.msg);
                        $(".getFail").show();
                    }
                }
            });
        }
    })
</script>
</body>
</html>